package net.easyjava.tools.json.filter;

import net.sf.json.util.PropertyFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IgnoreFieldProcessorImpl implements PropertyFilter {
	
	private static Logger logger = LoggerFactory.getLogger(IgnoreFieldProcessorImpl.class);

	private String[] fields;

	public IgnoreFieldProcessorImpl() {
		// empty
	}

	public IgnoreFieldProcessorImpl(String[] fields) {
		this.fields = fields;
	}

	public boolean apply(Object source, String name, Object value) {		

		if (fields != null && fields.length > 0) {
			if (ignore(name)) {
				return false;
			} else {
				return true;
			}
		}

		return true;
	}

	public boolean ignore(String name) {
		boolean b = false;
		for (String field : fields) {
			if (name.equals(field)) {
				b = true;
			}
		}
		return b;
	}

	public String[] getFields() {
		return fields;
	}

	public void setFields(String[] fields) {
		this.fields = fields;
	}
}
